﻿using CommunityToolkit.Mvvm.ComponentModel;
using LiveCharts;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WpfAppChart
{
    public class MainWindowViewModel : ObservableObject
    {
        private ChartValues<DataModel> _seriesValues;
        public ChartValues<DataModel> SeriesValues
        {
            get { return _seriesValues; }
            set { SetProperty(ref _seriesValues, value); }
        }

        public Func<double, string> XFormatter { get; set; }

        public MainWindowViewModel()
        {
            //设置x轴数据转换
            XFormatter = x =>
                x >= 0 ? default(DateTime).AddMinutes(x).ToString("MM-dd HH:mm") : "00-00 00:00";
            SeriesValues = new ChartValues<DataModel>();
            //添加测试数据
            //测试1 加入相同值的点
            //SeriesValues.Add(
            //    new DataModel { Value = 5, Time = DateTime.Parse("2024-1-30 19:00:00") }
            //);
            //SeriesValues.Add(
            //    new DataModel { Value = 5, Time = DateTime.Parse("2024-1-30 19:00:00") }
            //);

            ////测试2
            //var point = new DataModel { Value = 5, Time = DateTime.Parse("2024-1-30 19:00:00") };
            //SeriesValues.Add(point);
            //SeriesValues.Add(point);
        }
    }
}
